package cn.com.shadowless.xinning.view.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import cn.com.shadowless.xinning.R;
import cn.com.shadowless.xinning.model.order.AdniminiStrativeOrderInfo;
import cn.com.shadowless.xinning.view.BaseFragment;

/**
 * The type Admini strative child tab fragment.
 *
 * @param <T> the type parameter
 * @author sHadowLess
 */
public class AdminiStrativeChildTabFragment<T> extends BaseFragment {

    /**
     * The Main tab.
     */
    @BindView(R.id.main_tab)
    LinearLayout mainTab;

    private List<T> listBeans;
    private String dataName;
    private final String forMat = "%s\n公司预算金额：%s\n已报销：%s\n报销中：%s\n剩余可报销：%s";

    /**
     * Instantiates a new Company child tab fragment.
     *
     * @param listBeans the list beans
     * @param dataName  the data name
     */
    public AdminiStrativeChildTabFragment(List<T> listBeans, String dataName) {
        this.listBeans = listBeans;
        this.dataName = dataName;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_child_tab_layout;
    }

    @Override
    protected void initData() {
        switch (dataName) {
            case "报销主界面":
                List<AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.MainPageListBean> mainPageList = (List<AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.MainPageListBean>) listBeans;
                for (AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.MainPageListBean mainPageListBean : mainPageList) {
                    View view = LayoutInflater.from(mActivity).inflate(R.layout.fragment_admini_main_child_tab_item, null, false);
                    LinearLayout mainChildTab = view.findViewById(R.id.main_child_tab_item);
                    TextView mainChildTabTitle = view.findViewById(R.id.main_child_tab_title);
                    TextView mainChildTabProject = view.findViewById(R.id.main_child_tab_project);
                    TextView mainChildTabDepartName = view.findViewById(R.id.main_child_tab_departName);
                    TextView mainChildTabDutyPeople = view.findViewById(R.id.main_child_tab_dutyPeople);
                    TextView mainChildTabApplyCost = view.findViewById(R.id.main_child_tab_applyCost);
                    TextView mainChildTabShareProportion = view.findViewById(R.id.main_child_tab_shareProportion);
                    TextView mainChildTabAmount = view.findViewById(R.id.main_child_tab_amount);
                    TextView mainChildTabRemark = view.findViewById(R.id.main_child_tab_remark);
                    TextView mainChildTabFileNum = view.findViewById(R.id.main_child_tab_fileNum);
                    TextView mainChildTabBudget = view.findViewById(R.id.main_child_tab_Budget);

                    AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.MainPageListBean.BudgetItemObjectBean budgetItemObjectBean = mainPageListBean.getBudgetItemObject();
                    String budgetdirectory = mainPageListBean.getBudgetdirectory();
                    String department = mainPageListBean.getDepartment();
                    String principal = mainPageListBean.getPrincipal();
                    String applyAmount = getDecimal(mainPageListBean.getApplyAmount().doubleValue());
                    String shareRatio = getDecimal(mainPageListBean.getShareRatio().doubleValue());
                    String expenseAmount = getDecimal(mainPageListBean.getExpenseAmount().doubleValue());
                    String digest = mainPageListBean.getDigest();
                    String accessoryCount = getDecimal(mainPageListBean.getAccessoryCount().doubleValue());
                    String budgetInfo = budgetItemObjectBean.getBudgetInfo();
                    String allMoney = getDecimal(budgetItemObjectBean.getAllMoney().doubleValue());
                    String reimbursedMoney = getDecimal(budgetItemObjectBean.getReimbursedMoney().doubleValue());
                    String reimbursingMoney = getDecimal(budgetItemObjectBean.getReimbursingMoney().doubleValue());
                    String remainReimburseMoney = getDecimal(budgetItemObjectBean.getRemainReimburseMoney().doubleValue());
                    mainChildTabTitle.setText(budgetdirectory);
                    mainChildTabProject.setText(budgetdirectory);
                    mainChildTabDepartName.setText(department);
                    mainChildTabDutyPeople.setText(principal);
                    mainChildTabApplyCost.setText(applyAmount);
                    mainChildTabShareProportion.setText(shareRatio);
                    mainChildTabAmount.setText(expenseAmount);
                    mainChildTabRemark.setText(digest);
                    mainChildTabFileNum.setText(accessoryCount);
                    mainChildTabBudget.setText(String.format(forMat, budgetInfo, allMoney, reimbursedMoney, reimbursingMoney, remainReimburseMoney));
                    mainTab.addView(mainChildTab);
                }
                break;
            case "报销来源数据":
                List<AdniminiStrativeOrderInfo.DataBean.SourceFormListBean> sourceFormList = (List<AdniminiStrativeOrderInfo.DataBean.SourceFormListBean>) listBeans;
                for (AdniminiStrativeOrderInfo.DataBean.SourceFormListBean sourceFormListBean : sourceFormList) {
                    View view = LayoutInflater.from(mActivity).inflate(R.layout.fragment_admini_source_child_tab_item, null, false);
                    LinearLayout sourceTab = view.findViewById(R.id.source_child_tab_item);
                    TextView sourceChildTabTitle = view.findViewById(R.id.source_child_tab_title);
                    TextView sourceChildTabOrderId = view.findViewById(R.id.source_child_tab_orderId);
                    TextView sourceChildTabDate = view.findViewById(R.id.source_child_tab_date);
                    TextView sourceChildTabApplier = view.findViewById(R.id.source_child_tab_applier);
                    TextView sourceChildTabDepartName = view.findViewById(R.id.source_child_tab_departName);
                    TextView sourceChildTabBudgetProject = view.findViewById(R.id.source_child_tab_budgetProject);
                    TextView sourceChildTabApplyAmount = view.findViewById(R.id.source_child_tab_applyAmount);

                    String sourceOrderNo = sourceFormListBean.getSourceOrderNo();
                    String applyDateString = sourceFormListBean.getApplyDateString();
                    String proposer = sourceFormListBean.getProposer();
                    String applyDepartment = sourceFormListBean.getApplyDepartment();
                    String budgetdirectory = sourceFormListBean.getBudgetdirectory();
                    String applyAmount = sourceFormListBean.getApplyAmount();

                    sourceChildTabTitle.setText(dataName);
                    sourceChildTabOrderId.setText(sourceOrderNo);
                    sourceChildTabDate.setText(applyDateString);
                    sourceChildTabApplier.setText(proposer);
                    sourceChildTabDepartName.setText(applyDepartment);
                    sourceChildTabBudgetProject.setText(budgetdirectory);
                    sourceChildTabApplyAmount.setText(applyAmount);
                    mainTab.addView(sourceTab);
                }
                break;
            case "导入EXCEL明细":
                List<AdniminiStrativeOrderInfo.DataBean.ImportItemListBean> importItemList = (List<AdniminiStrativeOrderInfo.DataBean.ImportItemListBean>) listBeans;
                for (AdniminiStrativeOrderInfo.DataBean.ImportItemListBean importItemListBean : importItemList) {
                    View view = LayoutInflater.from(mActivity).inflate(R.layout.fragment_admini_import_child_tab_item, null, false);
                    LinearLayout importTab = view.findViewById(R.id.import_child_tab_item);
                    TextView importChildTabTitle = view.findViewById(R.id.import_child_tab_title);
                    TextView importChildTabProject = view.findViewById(R.id.import_child_tab_project);
                    TextView importChildTabDepartName = view.findViewById(R.id.import_child_tab_departName);
                    TextView importChildTabWorkNo = view.findViewById(R.id.import_child_tab_workNo);
                    TextView importChildTabEmployee = view.findViewById(R.id.import_child_tab_employee);
                    TextView importChildTabCost = view.findViewById(R.id.import_child_tab_cost);
                    TextView importChildTabRemark = view.findViewById(R.id.import_child_tab_remark);

                    String budgetDirectoryName = importItemListBean.getBudgetDirectoryName();
                    String departmentName = importItemListBean.getDepartmentName();
                    String workNo = importItemListBean.getWorkNo();
                    String employeeName = importItemListBean.getEmployeeName();
                    String amount = getDecimal(importItemListBean.getAmount().doubleValue());
                    String remark = importItemListBean.getRemark();

                    importChildTabTitle.setText(budgetDirectoryName);
                    importChildTabProject.setText(budgetDirectoryName);
                    importChildTabDepartName.setText(departmentName);
                    importChildTabWorkNo.setText(workNo);
                    importChildTabEmployee.setText(employeeName);
                    importChildTabCost.setText(amount);
                    importChildTabRemark.setText(remark);

                    mainTab.addView(importTab);
                }
                break;
            case "部门金额汇总":
                List<AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.AmountTotalListBean> amountTotalList = (List<AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.AmountTotalListBean>) listBeans;
                for (AdniminiStrativeOrderInfo.DataBean.ImportItemListBean.AmountTotalListBean amountTotalListBean : amountTotalList) {
                    View view = LayoutInflater.from(mActivity).inflate(R.layout.fragment_admini_amount_child_tab_item, null, false);
                    LinearLayout amountTab = view.findViewById(R.id.amount_child_tab_item);
                    TextView amountChildTabTitle = view.findViewById(R.id.amount_child_tab_title);
                    TextView amountChildTabDepartName = view.findViewById(R.id.amount_child_tab_departName);
                    TextView amountChildTabAmount = view.findViewById(R.id.amount_child_tab_amount);

                    String departmentName = amountTotalListBean.getDepartmentName();
                    String totalAmount = getDecimal(amountTotalListBean.getTotalAmount().doubleValue());

                    amountChildTabTitle.setText(dataName);
                    amountChildTabDepartName.setText(departmentName);
                    amountChildTabAmount.setText(totalAmount);

                    mainTab.addView(amountTab);
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void initView() {

    }
}
